package com.zr.daoImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.zr.dao.XzkcDaoljc;
import com.zr.model.Teacher;
import com.zr.util.JDBCUtil;

public class XzkcDaoImplljc implements XzkcDaoljc{

	@Override
	public boolean insertCourse(String cname, String classtime, String place, int tid) {
		boolean flag = false;
		StringBuffer sql = new StringBuffer("");
		sql.append(" INSERT INTO course(cname,classtime,place,tid)");
		sql.append(" VALUES(?,?,?,?)");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setString(1, cname);
			pst.setString(2, classtime);
			pst.setString(3, place);
			pst.setInt(4, tid);
			int i = pst.executeUpdate();
			if(i>0){
				flag=true;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}		
		return flag;
	}

	@Override
	public Teacher findTeacheridBytname(String tname) {
		Teacher t = new Teacher();
		StringBuffer sql = new StringBuffer();
		sql.append(" select teacher.tid from teacher");
		sql.append(" where teacher.tname=?");
		Connection con = JDBCUtil.getConnection();
		try {
			PreparedStatement pst = con.prepareStatement(sql.toString());
			pst.setString(1, tname);
			ResultSet rs = pst.executeQuery();
			while(rs.next()){
				t.setTid(rs.getInt("tid"));
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return t;
	}

}
